import React, { useEffect, useState } from 'react'
import { useParams } from 'react-router-dom'
import axios from 'axios'


export default function UserDetails() {
    console.log(useParams())
    const { id } = useParams()
    const [info, setInfo] = useState({})

    // useEffect的作用是componentDidMount
    useEffect(()=>{
        
        axios.get('https://api.github.com/users/' + id).then((value) => {
            setInfo(value.data)
            localStorage.setItem('userDetail', JSON.stringify(value.data))
        })
    },[])



    return (
        <div>
            <h3>{info.login}的用户详情</h3>
            <img src={info.avatar_url} alt="" />
        </div>
    )
}
